<?php
@header('Content-type:text/html;charset=UTF-8');
error_reporting(E_ALL);
date_default_timezone_set('Asia/shanghai');
//define("DEBUG",true);
define("DEBUG",false);
define('ROOT_DIR',dirname(__FILE__));
define('WEB_URL','http://127.0.0.1:2001/');
set_include_path('.'.PATH_SEPARATOR.'./library'.PATH_SEPARATOR.'./application/models/'.PATH_SEPARATOR.get_include_path());
require_once 'Zend/Loader.php';
require_once 'library/common.php';
Zend_Loader::registerAutoload();
Zend_Session::start();
$registry = Zend_Registry::getInstance(); 
$config=new Zend_Config_Ini('./application/config/config.ini',null,true);
Zend_Registry::set('config',$config);
$dbAdapter=Zend_Db::factory($config->general->db->adapter,$config->general->db->config->toArray());
$dbAdapter->query('set NAMES UTF8');
Zend_Db_Table::setDefaultAdapter($dbAdapter);
Zend_Registry::set('dbAdapter',$dbAdapter);
$view = new Zend_View();
$view->setScriptPath('./application/views/scripts/');
$registry['view'] = $view;

$auth=Zend_Auth::getInstance();
//$rewrite=new Custom_rewrite();
//$acl->isAllowed('member','admin')?"yes":"no";
//Zend_Registry::set('acl',$acl);
$columnMapping=array("log_level"=>'priority','log_name'=>'priorityName','log_msg'=>'message','log_time'=>'timestamp');
$writer=new Zend_Log_Writer_Db($dbAdapter,"plm_log",$columnMapping);
$logger = new Zend_Log($writer);
Zend_Registry::set('logger',$logger);





$frontController=Zend_Controller_Front::getInstance();
$frontController->addModuleDirectory('./application/models')
				->setBaseUrl('/')
				->setControllerDirectory('./application/controller')
				->setParam('setDefaultControllAlways',true)
				->registerPlugin(new Custom_rewrite());
$frontController->throwExceptions(true);	

$frontendOptions = array(
   'lifeTime' => 900, 
   'automatic_serialization' => true
);

$backendOptions = array(
    'cache_dir' => './tmp/' // Directory where to put the cache files
);

$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);

Zend_Registry::set('cache',$cache);
$options = array(
     'jquery_path' => '/public/js/jquery.js',
     'plugins' => array('Variables', 
                       'Html', 
                       'Database', 
                       'File' => array('base_path' => WEB_URL), 
					   'Cache'=> array('backend' => $cache->getBackend()), 
                       'Memory', 
                       'Time', 
                       'Registry', 
                       'Exception')
);

$debug = new ZFDebug_Controller_Plugin_Debug($options);


$frontController = Zend_Controller_Front::getInstance();
if(DEBUG){
$frontController->registerPlugin($debug);
}

$frontController->dispatch();

?>